public class MyHashSet {
    static class Node {
        int key;
        Node next;

        public Node(int key) {
            this.key = key;
        }
    }

    public Node[] array;
    public int usedSize;
    public static final double loadFactor = 0.75;
    public MyHashSet() {
        this.array = new MyHashSet.Node[10];
    }


    public void add(int key) {
        if(contains(key)) {
            return;
        }
        int index = key % array.length;
        Node node = new Node(key);
        node.next = array[index];
        array[index] = node;
        usedSize++;
        if(calculateLoadFactor() >= loadFactor) {
            resize();
        }
    }

    public double calculateLoadFactor() {
        return usedSize*1.0 / array.length;
    }

    public void resize() {
        Node[] newArray = new Node[array.length*2];
        for(int i =0; i < array.length; i++) {
            Node cur = array[i];
            while(cur != null) {
                int index = cur.key % newArray.length;
                Node curNext = cur.next;
                cur.next = newArray[index];
                newArray[index] = cur;
                cur = curNext;
            }
        }
        array= newArray;
    }

    public void remove(int key) {
        int index = key % array.length;
        Node cur = array[index];
        if(cur == null) {
            return;
        }
        if( cur != null && cur.key == key) {
            array[index] = cur.next;
            return;
        }else {
            while(cur != null) {
                Node prve = cur;
                cur = cur.next;
                if( cur != null && cur.key == key) {
                    prve.next = cur.next;
                    return;
                }
            }
        }
    }

    public boolean contains(int key) {
        int index = key % array.length;
        Node cur = array[index];
        while(cur != null) {
            if(cur.key == key) {
                return true;
            }
            cur = cur.next;
        }
        return false;
    }
}
